# _*_ coding : utf-8 _*_
# @Time : 2022/8/13 11:20
# @Author : Moonquake
# @File : 26.selenium_交互
# @Project : python
from selenium.webdriver.common.by import By
from selenium import webdriver
from selenium.webdriver.edge.webdriver import Service

path = Service('MicrosoftWebDriver.exe')

browser = webdriver.Edge(service = path)

url = 'https://www.baidu.com'

browser.get(url)

import time
time.sleep(2)

# 获取文本框的对象
input = browser.find_element(By.ID,'kw')

# 文本框中输入周杰伦
input.send_keys('周杰伦')

time.sleep(2)

# 获取百度一下的按钮
button = browser.find_element(By.ID,'su')

# 点击按钮
button.click()

time.sleep(2)

# 滑到底部
js_bottom = 'document.documentElement.scrollTop=10000'
browser.execute_script(js_bottom)

time.sleep(2)
# 获取下一页按钮
next = browser.find_element(By.XPATH,'//a[@class="n"]')
# 点击下一页
next.click()
time.sleep(2)

browser.execute_script(js_bottom)
time.sleep(2)
# 后退
browser.back()
time.sleep(2)
# 退出
browser.quit()